package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.WarehouseDept;
import lp.xian.materials.service.IWarehouseDeptService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 仓库分类Controller
 *
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/warehouseDept/warehouseDept")
public class WarehouseDeptController extends BaseController
{
    @Autowired
    private IWarehouseDeptService warehouseDeptService;

    /**
     * 查询仓库分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:list')")
    @GetMapping("/list")
    public AjaxResult list(WarehouseDept warehouseDept)
    {
        List<WarehouseDept> list = warehouseDeptService.selectWarehouseDeptList(warehouseDept);
        return success(list);
    }

    /**
     * 导出仓库分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:export')")
    @Log(title = "仓库分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehouseDept warehouseDept)
    {
        List<WarehouseDept> list = warehouseDeptService.selectWarehouseDeptList(warehouseDept);
        ExcelUtil<WarehouseDept> util = new ExcelUtil<WarehouseDept>(WarehouseDept.class);
        util.exportExcel(response, list, "仓库分类数据");
    }

    /**
     * 获取仓库分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:query')")
    @GetMapping(value = "/{warehouseDeptId}")
    public AjaxResult getInfo(@PathVariable("warehouseDeptId") Integer warehouseDeptId)
    {
        return success(warehouseDeptService.selectWarehouseDeptByWarehouseDeptId(warehouseDeptId));
    }

    /**
     * 新增仓库分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:add')")
    @Log(title = "仓库分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseDept warehouseDept)
    {
        return toAjax(warehouseDeptService.insertWarehouseDept(warehouseDept));
    }

    /**
     * 修改仓库分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:edit')")
    @Log(title = "仓库分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseDept warehouseDept)
    {
        return toAjax(warehouseDeptService.updateWarehouseDept(warehouseDept));
    }

    /**
     * 删除仓库分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseDept:warehouseDept:remove')")
    @Log(title = "仓库分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{warehouseDeptIds}")
    public AjaxResult remove(@PathVariable Integer[] warehouseDeptIds)
    {
        return toAjax(warehouseDeptService.deleteWarehouseDeptByWarehouseDeptIds(warehouseDeptIds));
    }
}
